package com.unbox.common.annotation.scan;

import com.unbox.common.annotation.entity.AnnotionEnitty;
import java.lang.annotation.Annotation;

/**
 * 扫描自定义注解
 */
public class UnboxDefaultAnnotationScan implements UnBoxAnnotationScan {

    /**
     * 返回所有方法相关内容
     */
    @Override
    public AnnotionEnitty scanMethodAnnotation(Object obj, String method, Object[] types) throws NoSuchMethodException {
        AnnotionEnitty annotionEnitty = new AnnotionEnitty();
        Class cls = obj.getClass();
        Class[] parameterTypes = new Class[types.length];
        for(int i =0; i < types.length; i ++) {
            parameterTypes[i] = types[i].getClass();
        }
        annotionEnitty.setParameterTypes(parameterTypes);
        Annotation[] annotations = cls.getMethod(method, parameterTypes).getAnnotations();
        annotionEnitty.setAnnotations(annotations);
        annotionEnitty.setValues(types);
        annotionEnitty.setObj(obj);
        annotionEnitty.setMethodName(method);
        annotionEnitty.setObjClass(cls);
        return annotionEnitty;
    }
}
